package net.koodar.forge.system.role.manager;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import net.koodar.forge.system.role.dao.UserRoleMapper;
import net.koodar.forge.system.role.model.entity.UserRole;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author liyc
 */
@Service
@RequiredArgsConstructor
public class UserRoleManager extends ServiceImpl<UserRoleMapper, UserRole> {

    private final UserRoleMapper userRoleMapper;

    public void save(Long userId, Long roleId) {
        UserRole userRole = new UserRole();
        userRole.setUserId(userId);
        userRole.setRoleId(roleId);
        userRoleMapper.insert(userRole);
    }

    public List<UserRole> findAllByUserId(@NonNull Long userId) {
        return userRoleMapper.selectList(Wrappers.<UserRole>lambdaQuery().eq(UserRole::getUserId, userId));
    }

}
